package com.gethb.prod.controller;

import com.gethb.data.mdo.KlinesDo;
import com.gethb.data.mdo.TickerDo;
import com.gethb.prod.service.IGetKlineService;
import com.gethb.prod.vo.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/kline")
public class KLineController {

    // 用户获取Kline数据实现类
    @Resource(name = "getKlineService")
    private IGetKlineService iGetKlineService;


    @ResponseBody
    @GetMapping(value = "/marketData")
    public Result<MarketDataOutVo> getMarketData(KlineDataInVo inVo) {
        //
        try {
            List<KlinesDo> list = iGetKlineService.getList(inVo);
            TickerDo ticker = iGetKlineService.getTicker(inVo.getSymbol());
            MarketDataOutVo vo = new MarketDataOutVo();
            vo.setTicker(ticker);
            vo.setList(list);
            return Result.success(vo);
        } catch (Exception exception) {
            return Result.exception(exception.getMessage());
        }
    }

    @ResponseBody
    @GetMapping(value = "/list")
    public Result<List<KlinesDo>> getLastData(KlineDataInVo inVo) {
        //
        try {
            return Result.success(iGetKlineService.getList(inVo));
        } catch (Exception exception) {
            return Result.exception(exception.getMessage());
        }
    }
}
